<?php 
/*
 module:		礼币管理
 create_time:	2022-04-04 16:22:00
 author:	陕西格创
 contact:		
*/

namespace app\api\controller;

use app\api\model\Member as MemberModel;
use think\facade\Db;

class ZhTopCard extends Common {


	function index(){

        $list =   Db::name('zh_top_card')->field('id,name,price,day')->where('status',1)->select();

		return $this->ajaxReturn($this->successCode,'返回成功',$list);
	}


    function getTopDay(){
        $wxapp_id = $this->request->get('wxapp_id');
        $uId      = $this->getUid();
        if (!$wxapp_id) {
            return $this->ajaxReturn($this->errorCode, '缺少平台参数');
        }
        $user = MemberModel::where(['uid' => $uId, 'wxapp_id' => $wxapp_id])->find();
        if (!$user) {
            return $this->ajaxReturn($this->errorCode, '未知用户');
        }
        //算出置顶卡剩余时间
        if($user['top_card_expiry'] && $user['top_card_expiry']>time()){
            $topDay = ceil(($user['top_card_expiry']-time())/86400);
        }else{
            $topDay=0;
        }

        return $this->ajaxReturn($this->successCode,'返回成功',$topDay);
    }


}

